﻿@model FTBS.Models.Entities.Film
@using FTBS.Models.Entities
@{
    ViewBag.Title = "Trang chủ";
    Layout = "~/Views/Shared/_Layout.cshtml";
    var testValue = (string)ViewBag.Test;
    var theatersList = (SelectList)ViewBag.ListTheaters;
    var filmsList = (SelectList)ViewBag.ListFilms;
    var showtimesList = (SelectList)ViewBag.ListShowTimes;
    var datesList = (SelectList)ViewBag.ListDates;

    List<Film> lisHotFilms = ViewBag.ListHotFilms;
    
}
<style>
    .description {
        display: -webkit-box;
        max-width: 400px;
        margin: 0 auto;
        font-size: 12px;
        line-height: 1px;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .limitName {
        line-height: none;
        display: -webkit-box;
        margin: 0 auto;
        font-size: 12px;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
    }
</style>

<body onload="getListObjectToShow()">

    <div style="display: inline-block; height: 400px; width: 30%; background-color: black; margin-top: 3px; vertical-align: top; margin-left: 20px">
        <div>
            <table style="margin-left: 10px; margin-top: 20px; background-color: black;">
                <tr>
                    <td colspan="2">
                        <h3  style="color: white; text-align:center">Mua Ngay!!!</h3>
                    </td>
                </tr>
                <tr>
                    <td>Phim:</td>
                    <td>
                        @Html.DropDownListFor(model => model.Name, filmsList, "--- Chọn phim ---", new { value = 0, id = "cbbFilm" })
                    </td>
                </tr>
                <tr>
                    <td>Rạp:</td>
                    <td>
                        @Html.DropDownListFor(model => model.Name, theatersList, "--- Chọn rạp ---", new { value = 0, id = "cbbTheater" })
                    </td>
                </tr>
                <tr>
                    <td>Ngày:</td>
                    <td>
                        @Html.DropDownListFor(model => model.Name, datesList, "--- Chọn ngày ---", new { value = 0, id = "cbbDate" })
                    </td>
                </tr>
                <tr>
                    <td>Giờ:</td>
                    <td>
                        @Html.DropDownListFor(model => model.Name, showtimesList, "--- Chọn giờ ---", new { value = 0, id = "cbbShowTime" })
                    </td>
                </tr>
            </table>
        </div>
                <hr />
        <div style="margin-left: 10px; margin-top: 20px;">
            <input id="btnBuy" class="info" type="submit" value="Mua vé" />
        </div>
    </div>
    <div style="display: inline-block; width: 65%; margin-left: 10px">
        <div class="carousel" id="carousel2" style="margin-top: 3px">
            @if (lisHotFilms.Count() > 0)
            {
                foreach (var item in lisHotFilms)
                {
                <div class="slide">
                    <img src="~/Image/FilmImage/Horizontal/@item.ImageURL" class="cover1" style="width:100%;height:400px" />
                </div>
                }
            }
            <a class="controls left"><i class="icon-arrow-left-3"></i></a>
            <a class="controls right"><i class="icon-arrow-right-3"></i></a>
        </div>
    </div>

    <!-- CÓ THỂ BẠN MUỐN XEM -->
    <div id="filmSuggestionGuest">
        @Html.Partial("FilmsSuggestion", new List<FTBS.Models.Entities.Film>())
    </div>

    <!-- CÁC PHIM ĐANG KHUYẾN MÃI -->

    <div id="partialFilmPromotion">
        @Html.Partial("FilmsPromotion", (List<FTBS.Models.Entities.Concert.FilmConcertEntity>)ViewBag.ListFilmPromotion)
    </div>

    <!-- CÁC PHIM ĐANG CHIẾU -->
    <div id="partialFilmShowing">
        @Html.Partial("FilmShowing", (List<FTBS.Models.Entities.Film>)ViewBag.ListFilmShowing)
    </div>

    <!-- PHIM SẮP CHIẾU* -->
    <div id="partialFilmCommingSoon">
        @Html.Partial("FilmsCommingSoon", (List<FTBS.Models.Entities.Concert.FilmConcertEntity>)ViewBag.ListFilmCommingSoon)
    </div>

    <!-- CÁC RẠP GẦN NHÀ BẠN -->
    <div id="partialNearTheaterGuest">
        @Html.Partial("NearestTheater", new List<FTBS.Models.Entities.Concert.TheaterConcertEntity>())
    </div>
</body>


<script>
    var checkTheater = 0;
    var checkFilm = 0;
    var ready=0;

    $("#cbbFilm").change(function () {
        if ($("#cbbFilm").val() == 0) {
            checkFilm = 0;
            GetAllTheaters();
        }
        else {
            checkFilm = 1;
            GetAllTheaters();
            if (CheckReadyToGetDate()) {
                GetAllDates()
            }
        }
    })
    $("#cbbTheater").change(function () {
        
        if ($("#cbbTheater").val() == 0) {
            checkTheater = 0;
            //GetAllFilms();
        }
        else {
            checkTheater = 1;
            //GetAllFilms();
            if (CheckReadyToGetDate()) {
                GetAllDates()
            }
        }
    })
    $("#cbbDate").change(function () {
        GetShowtimes();
    })
    $("#btnBuy").click(function () {
        var date = $("#Date").val();
        var theater = $("#cbbTheater").val();
        var film = $("#cbbFilm").val();
        var showtime = $("#cbbShowTime").val();
        if (film != 0 && theater != 0 && showtime != 0) {
            window.location.href = "~/Schedule/BookingATicket?date=" + date + "&theaterId=" + theater + "&filmId=" + film + "&showtimeId=" + showtime
        }
    })

    function CheckReadyToGetDate() {
        if (checkFilm == 1 && checkTheater == 1) {
            ready = 1;
        }
        return ready;
    }

    function GetAllTheaters() {
        $.ajax({
            type: "GET",
            url: '@Url.Action("GetTheatesrByFilm", "Home")',
            data: { filmId: $("#cbbFilm").val() },
            success: function (data) {
                //console.log(data);
                var items = [];
                items.push("<option value=0>--- Chọn Rạp ---</option>");
                $.each(data, function (key, value) {
                    items.push("<option value=" + value.Value + ">" + value.Text + "</option>");
                });
                //console.log(items);
                $("#cbbTheater").html(items.join(' '));
            }
        })
    }

    function GetAllFilms() {
        $.ajax({
            type: "GET",
            url: '@Url.Action("GetFilmsByTheater", "Home")',
            data: { theaterId: $("#cbbTheater").val() },
            success: function (data) {
                //console.log(data);
                var items = [];
                items.push("<option value=0>--- Chọn phim ---</option>");
                $.each(data, function (key, value) {
                    items.push("<option value=" + value.Value + ">" + value.Text + "</option>");
                });
                //console.log(items);
                $("#cbbFilm").html(items.join(' '));
            }
        })
    }

    function GetAllDates() {
        $.ajax({
            type: "GET",
            url: '@Url.Action("GetDates", "Home")',
            data: { filmId: $("#cbbFilm").val(), theaterId: $("#cbbTheater").val() },
            success: function (data) {
                //console.log(data);
                var items = [];
                items.push("<option>--- Chọn Ngày---</option>");
                $.each(data, function (Key, Value) {
                    items.push("<option value=" + value.Value + ">" + value.Text + "</option>");
                });
                //console.log(items);
                $("#cbbFilm").html(items.join(' '));
            }
        })
    }

    function GetShowtimes() {
        $.ajax({
            type: "GET",
            url: '@Url.Action("GetShowtimes", "Home")',
            data: { date: $("#cbbDate").val(), filmId: $("#cbbFilm").val(), theaterId: $("#cbbTheater").val() },
            success: function (data) {
                //console.log(data);
                var items = [];
                items.push("<option>--- Chọn giờ ---</option>");
                $.each(data, function (key, value) {
                    items.push("<option value=" + value.Value + ">" + value.Text + "</option>");
                });
                //console.log(items);
                $("#Date").html(items.join(' '));
            }
        })
    }
</script>

@*<script src="http://maps.google.com/maps/api/js?sensor=true" type="text/javascript"></script>
<script>

    function getListObjectToShow() {
        //Get list nearest theater
        getLocation();
        //Get list film suggest
        loadSuggestionForGuest();
    }

    function loadSuggestionForGuest() {
        var listCategoryResult = JSON.stringify(getLocalStorageViewResult());
        $.ajax({
            url: "/Home/GetListFilmSuggestionGuest",
            type: "GET",
            data: { listCategoryView: listCategoryResult },
            success: function (data) {
                $('#filmSuggestionGuest').html(data);
            },
            error: function (data) {
                alert("fail");
            }
        });
    }

    function getLocation() {
        navigator.geolocation.getCurrentPosition(callback);
    }

    function callback(position) {
        var listPosition = JSON.stringify(getPositionLocalStorage());
        if (listPosition == "null") {
            $.ajax({
                url: "/Home/NearestTheater",
                type: "POST",
                data: { latitude: position.coords.latitude, longitude: position.coords.longitude },
                success: function (data) {
                    $('#partialNearTheaterGuest').html(data);
                },
                error: function (data) {
                    alert("fail");
                }
            });
        }
        else {
            var listNearestTheater = JSON.stringify(getNearestTheaterListLocalStorage());
            $.ajax({
                url: "/Home/NearestTheaterExisted",
                type: "POST",
                data: { latitude: position.coords.latitude, longitude: position.coords.longitude, listPositionExist: listPosition, listNearestTheaterExisted: listNearestTheater },
                success: function (data) {
                    $('#partialNearTheaterGuest').html(data);
                },
                error: function (data) {
                    alert("fail");
                }
            });
        }
    };
</script>*@

<script>
    $(function () {
        $("#carousel2").carousel({
            width: "100%",
            height: 400,
            effect: 'slide',
            markers: {
                show: true,
                type: 'cycle',
                position: 'bottom-right'
            }
        });
    })
</script>

